1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.SpaceDrawer;
26 
27 private import gio.Settings;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import glib.Variant;
31 private import gobject.ObjectG;
32 private import sourceview.c.functions;
33 public  import sourceview.c.types;
34 
35 
36 /**
37  * Represent white space characters with symbols.
38  * 
39  * #GtkSourceSpaceDrawer provides a way to visualize white spaces, by drawing
40  * symbols.
41  * 
42  * Call [method@View.get_space_drawer] to get the `GtkSourceSpaceDrawer`
43  * instance of a certain [class@View].
44  * 
45  * By default, no white spaces are drawn because the
46  * [property@SpaceDrawer:enable-matrix] is %FALSE.
47  * 
48  * To draw white spaces, [method@SpaceDrawer.set_types_for_locations] can
49  * be called to set the [property@SpaceDrawer:matrix] property (by default all
50  * space types are enabled at all locations). Then call
51  * [method@SpaceDrawer.set_enable_matrix].
52  * 
53  * For a finer-grained method, there is also the [class@Tag]'s
54  * [property@Tag:draw-spaces] property.
55  * 
56  * # Example
57  * 
58  * To draw non-breaking spaces everywhere and draw all types of trailing spaces
59  * except newlines:
60  * ```c
61  * gtk_source_space_drawer_set_types_for_locations (space_drawer,
62  * GTK_SOURCE_SPACE_LOCATION_ALL,
63  * GTK_SOURCE_SPACE_TYPE_NBSP);
64  * 
65  * gtk_source_space_drawer_set_types_for_locations (space_drawer,
66  * GTK_SOURCE_SPACE_LOCATION_TRAILING,
67  * GTK_SOURCE_SPACE_TYPE_ALL &
68  * ~GTK_SOURCE_SPACE_TYPE_NEWLINE);
69  * 
70  * gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
71  * ```
72  * 
73  * # Use-case: draw unwanted white spaces
74  * 
75  * A possible use-case is to draw only unwanted white spaces. Examples:
76  * 
77  * - Draw all trailing spaces.
78  * - If the indentation and alignment must be done with spaces, draw tabs.
79  * 
80  * And non-breaking spaces can always be drawn, everywhere, to distinguish them
81  * from normal spaces.
82  */
83 public class SpaceDrawer : ObjectG
84 {
85 	/** the main Gtk struct */
86 	protected GtkSourceSpaceDrawer* gtkSourceSpaceDrawer;
87 
88 	/** Get the main Gtk struct */
89 	public GtkSourceSpaceDrawer* getSpaceDrawerStruct(bool transferOwnership = false)
90 	{
91 		if (transferOwnership)
92 			ownedRef = false;
93 		return gtkSourceSpaceDrawer;
94 	}
95 
96 	/** the main Gtk struct as a void* */
97 	protected override void* getStruct()
98 	{
99 		return cast(void*)gtkSourceSpaceDrawer;
100 	}
101 
102 	/**
103 	 * Sets our main struct and passes it to the parent class.
104 	 */
105 	public this (GtkSourceSpaceDrawer* gtkSourceSpaceDrawer, bool ownedRef = false)
106 	{
107 		this.gtkSourceSpaceDrawer = gtkSourceSpaceDrawer;
108 		super(cast(GObject*)gtkSourceSpaceDrawer, ownedRef);
109 	}
110 
111 
112 	/** */
113 	public static GType getType()
114 	{
115 		return gtk_source_space_drawer_get_type();
116 	}
117 
118 	/**
119 	 * Creates a new #GtkSourceSpaceDrawer object.
120 	 *
121 	 * Useful for storing space drawing settings independently of a [class@View].
122 	 *
123 	 * Returns: a new #GtkSourceSpaceDrawer.
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this()
128 	{
129 		auto __p = gtk_source_space_drawer_new();
130 
131 		if(__p is null)
132 		{
133 			throw new ConstructionException("null returned by new");
134 		}
135 
136 		this(cast(GtkSourceSpaceDrawer*) __p, true);
137 	}
138 
139 	/**
140 	 * Binds the [property@SpaceDrawer:matrix] property to a [class@Gio.Settings] key.
141 	 *
142 	 * The [class@Gio.Settings] key must be of the same type as the
143 	 * [property@SpaceDrawer:matrix] property, that is, `"au"`.
144 	 *
145 	 * The [method@Gio.Settings.bind] function cannot be used, because the default GIO
146 	 * mapping functions don't support [struct@GLib.Variant] properties (maybe it will be
147 	 * supported by a future GIO version, in which case this function can be
148 	 * deprecated).
149 	 *
150 	 * Params:
151 	 *     settings = a #GSettings object.
152 	 *     key = the @settings key to bind.
153 	 *     flags = flags for the binding.
154 	 */
155 	public void bindMatrixSetting(Settings settings, string key, GSettingsBindFlags flags)
156 	{
157 		gtk_source_space_drawer_bind_matrix_setting(gtkSourceSpaceDrawer, (settings is null) ? null : settings.getSettingsStruct(), Str.toStringz(key), flags);
158 	}
159 
160 	/**
161 	 * Returns: whether the #GtkSourceSpaceDrawer:matrix property is enabled.
162 	 */
163 	public bool getEnableMatrix()
164 	{
165 		return gtk_source_space_drawer_get_enable_matrix(gtkSourceSpaceDrawer) != 0;
166 	}
167 
168 	/**
169 	 * Gets the value of the [property@SpaceDrawer:matrix] property, as a [struct@GLib.Variant].
170 	 *
171 	 * An empty array can be returned in case the matrix is a zero matrix.
172 	 *
173 	 * The [method@SpaceDrawer.get_types_for_locations] function may be more
174 	 * convenient to use.
175 	 *
176 	 * Returns: the #GtkSourceSpaceDrawer:matrix value as a new floating #GVariant
177 	 *     instance.
178 	 */
179 	public Variant getMatrix()
180 	{
181 		auto __p = gtk_source_space_drawer_get_matrix(gtkSourceSpaceDrawer);
182 
183 		if(__p is null)
184 		{
185 			return null;
186 		}
187 
188 		return new Variant(cast(GVariant*) __p, true);
189 	}
190 
191 	/**
192 	 * If only one location is specified, this function returns what kind of
193 	 * white spaces are drawn at that location.
194 	 *
195 	 * The value is retrieved from the [property@SpaceDrawer:matrix] property.
196 	 *
197 	 * If several locations are specified, this function returns the logical AND for
198 	 * those locations. Which means that if a certain kind of white space is present
199 	 * in the return value, then that kind of white space is drawn at all the
200 	 * specified @locations.
201 	 *
202 	 * Params:
203 	 *     locations = one or several #GtkSourceSpaceLocationFlags.
204 	 *
205 	 * Returns: a combination of #GtkSourceSpaceTypeFlags.
206 	 */
207 	public GtkSourceSpaceTypeFlags getTypesForLocations(GtkSourceSpaceLocationFlags locations)
208 	{
209 		return gtk_source_space_drawer_get_types_for_locations(gtkSourceSpaceDrawer, locations);
210 	}
211 
212 	/**
213 	 * Sets whether the [property@SpaceDrawer:matrix] property is enabled.
214 	 *
215 	 * Params:
216 	 *     enableMatrix = the new value.
217 	 */
218 	public void setEnableMatrix(bool enableMatrix)
219 	{
220 		gtk_source_space_drawer_set_enable_matrix(gtkSourceSpaceDrawer, enableMatrix);
221 	}
222 
223 	/**
224 	 * Sets a new value to the [property@SpaceDrawer:matrix] property, as a [struct@GLib.Variant].
225 	 *
226 	 * If @matrix is %NULL, then an empty array is set.
227 	 *
228 	 * If @matrix is floating, it is consumed.
229 	 *
230 	 * The [method@SpaceDrawer.set_types_for_locations] function may be more
231 	 * convenient to use.
232 	 *
233 	 * Params:
234 	 *     matrix = the new matrix value, or %NULL.
235 	 */
236 	public void setMatrix(Variant matrix)
237 	{
238 		gtk_source_space_drawer_set_matrix(gtkSourceSpaceDrawer, (matrix is null) ? null : matrix.getVariantStruct());
239 	}
240 
241 	/**
242 	 * Modifies the [property@SpaceDrawer:matrix] property at the specified
243 	 * @locations.
244 	 *
245 	 * Params:
246 	 *     locations = one or several #GtkSourceSpaceLocationFlags.
247 	 *     types = a combination of #GtkSourceSpaceTypeFlags.
248 	 */
249 	public void setTypesForLocations(GtkSourceSpaceLocationFlags locations, GtkSourceSpaceTypeFlags types)
250 	{
251 		gtk_source_space_drawer_set_types_for_locations(gtkSourceSpaceDrawer, locations, types);
252 	}
253 }